package Model;

import java.util.ArrayList;
import java.util.Date;
import org.w3c.dom.Element;

import DAO.XML_DAO;

public class Task implements ISerializable {

    public String taskName; // primary key
    public String taskDescription;
    public Date taskStartDate;
    public Date taskFinishDate;
    public int taskPorcent;

    public Task(String name, String description, Date startDate, Date finishDate, int porcent) {
        this.taskName = name;
        this.taskDescription = description;
        this.taskStartDate = startDate;
        this.taskFinishDate = finishDate;
        this.taskPorcent = porcent;
    }

    public Task() {
    }

    public void print(String indent, StringBuilder sb) {
        sb.append(indent).append("Task ").append("\n");
        sb.append(indent).append("Name: ").append(taskName).append("\n");
        sb.append(indent).append("Description: ").append(taskDescription).append("\n");
        sb.append(indent).append("StartDate: ").append(XML_DAO.fromDateToString(taskStartDate)).append("\n");
        sb.append(indent).append("FinishDate: ").append(XML_DAO.fromDateToString(taskFinishDate)).append("\n");
        sb.append(indent).append("Porcent: ").append(taskPorcent).append("\n");
    }

    public String toText(Date startDate) {
        StringBuilder sb = new StringBuilder();
        int daysDuration = (int) ( this.taskFinishDate.getTime() - this.taskStartDate.getTime() ) / (1000 * 60 * 60 * 24);
        int daysAfterStart = (int) ( this.taskStartDate.getTime() - startDate.getTime() ) / (1000 * 60 * 60 * 24);
        
        sb.append(this.taskName).append("|");
        sb.append(this.taskDescription).append("|");
        sb.append(XML_DAO.fromDateToString(taskStartDate)).append("|");
        sb.append(XML_DAO.fromDateToString(taskFinishDate)).append("|");
        sb.append(daysDuration).append("|");
        sb.append(daysAfterStart).append("|");
        sb.append(this.taskPorcent).append("|");
        
        sb.append("--");
        
        return sb.toString();
    }
}
